package io.chenglicun.modules.check.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.chenglicun.common.service.impl.CrudServiceImpl;
import io.chenglicun.common.constant.Constant;
import io.chenglicun.common.utils.ConvertUtils;
import io.chenglicun.modules.check.dao.ClcFileManageDao;
import io.chenglicun.modules.check.dto.ClcFileManageDTO;
import io.chenglicun.modules.check.entity.ClcFileManageEntity;
import io.chenglicun.modules.check.service.ClcFileManageService;
import io.chenglicun.modules.security.user.SecurityUser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 文件管理
 *
 * @author HB 137664951@qq.com
 * @since 1.0 2023-11-29
 */
@Service
public class ClcFileManageServiceImpl extends CrudServiceImpl<ClcFileManageDao, ClcFileManageEntity, ClcFileManageDTO> implements ClcFileManageService {

    @Override
    public QueryWrapper<ClcFileManageEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<ClcFileManageEntity> wrapper = new QueryWrapper<>();


        return wrapper;
    }

    @Override
    public List<ClcFileManageDTO> getList(Long... sourceIds) {
        List<ClcFileManageEntity> entities = baseDao.selectList(
                new QueryWrapper<ClcFileManageEntity>().lambda().in(ClcFileManageEntity::getSourceId, Arrays.asList(sourceIds)));
        return ConvertUtils.sourceToTarget(entities, ClcFileManageDTO.class);
    }

    @Override
    @Transactional
    public void deleteBySourceIds(Integer type, Long... sourceIds) {
        if (type == null)
            baseDao.delete(new QueryWrapper<ClcFileManageEntity>().lambda()
                    .in(ClcFileManageEntity::getSourceId, Arrays.asList(sourceIds)));
        else
            baseDao.delete(new QueryWrapper<ClcFileManageEntity>().lambda()
                    .in(ClcFileManageEntity::getSourceId, Arrays.asList(sourceIds))
                    .eq(ClcFileManageEntity::getSourceType, type));
    }
}